package br.upis.pf1.util;

import java.io.IOException;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;

public class FacesContextUtil {

	private static final String HIBERNATE_SESSION = "hibernate_session";
	private static final String APPLICATION = "/agente-eventos/";
	
	public static void setRequestSession(Session session) {
		FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(HIBERNATE_SESSION, session);
	}
	
	public static Session getRequestSession() {
		return (Session)FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(HIBERNATE_SESSION);
	}

	public static Object getSessionAttribute(String atributo) {
		return ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).getAttribute(atributo);
	}
	
	public static void setNavegacao(String destino) {
		FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, destino);
	}
	
	public static void setNavegacao2(String destino) {
		try {
			FacesContext.getCurrentInstance().getExternalContext().redirect(APPLICATION + destino);
		} catch (IOException e) {}
	}
	
}
